package com.xinghai.web.controller.dingtalk;

import com.xinghai.common.annotation.Log;
import com.xinghai.common.core.controller.BaseController;
import com.xinghai.common.core.page.TableDataInfo;
import com.xinghai.common.enums.BusinessType;
import com.xinghai.common.utils.poi.ExcelUtil;
import com.xinghai.system.domain.dto.*;
import com.xinghai.system.domain.vo.XhStaticsReportQueryVo;
import com.xinghai.system.service.XhStaticsReportService;
import com.xinghai.system.util.XHConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报表接口api
 *
 * @author smy
 */
@Slf4j
@RestController
@RequestMapping("/static/report")
public class XhStaticsReportController extends BaseController {

    @Autowired
    private XhStaticsReportService xhStaticsReportService;

    /** ============================ 运输明细模板 ============================ **/

    /**
     * 运输明细模板-查询
     *
     * @return
     */
    @Log(title = "运输明细模板")
    @GetMapping("/transfer/detail/page")
    public TableDataInfo transferDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<TransferDetailDTO> detailList = xhStaticsReportService.transferDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 运输明细模板-导出
     */
    @Log(title = "运输明细模板-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/transfer/detail/export")
    public void transferDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<TransferDetailDTO> detailList = xhStaticsReportService.transferDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<TransferDetailDTO> util = new ExcelUtil<TransferDetailDTO>(TransferDetailDTO.class);
        util.exportExcel(response, detailList, "运输明细模板");
    }

    /** ============================ 打包耗材统计明细 ============================ **/

    /**
     * 打包耗材统计明细-查询
     *
     * @return
     */
    @Log(title = "打包耗材统计明细查询")
    @GetMapping("/consumables/detail/page")
    public TableDataInfo consumablesDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<ConsumablesDetailDTO> detailList = xhStaticsReportService.consumablesDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 打包耗材统计明细-导出
     */
    @Log(title = "打包耗材统计明细-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/consumables/detail/export")
    public void consumablesDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<ConsumablesDetailDTO> detailList = xhStaticsReportService.consumablesDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<ConsumablesDetailDTO> util = new ExcelUtil<ConsumablesDetailDTO>(ConsumablesDetailDTO.class);
        util.exportExcel(response, detailList, "打包耗材统计明细");
    }

    /** ============================ 扣款单明细 ============================ **/

    /**
     * 扣款单明细-查询
     *
     * @return
     */
    @Log(title = "扣款单明细查询")
    @GetMapping("/debit/detail/page")
    public TableDataInfo debitDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<DebitDetailDTO> detailList = xhStaticsReportService.debitDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 扣款单明细-导出
     */
    @Log(title = "扣款单明细-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/debit/detail/export")
    public void debitDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<DebitDetailDTO> detailList = xhStaticsReportService.debitDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<DebitDetailDTO> util = new ExcelUtil<DebitDetailDTO>(DebitDetailDTO.class);
        String sheetName = "扣款单明细-"+(XHConstant.STR_0.equals(xhStaticsReportQueryVo.getDateFlag())?xhStaticsReportQueryVo.getDateYearMonth():xhStaticsReportQueryVo.getDateYear());
        util.exportExcel(response, detailList, sheetName);
    }

    /** ============================ 各项目运输费用 ============================ **/

    /**
     * 各项目运输费用-查询
     *
     * @return
     */
    @Log(title = "各项目运输费用")
    @GetMapping("/project/fee/detail/page")
    public TableDataInfo projectFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<ProjectFeeDetailDTO> detailList = xhStaticsReportService.projectFeeDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 各项目运输费用-导出
     */
    @Log(title = "各项目运输费用-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/project/fee/detail/export")
    public void projectFeeDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<ProjectFeeDetailDTO> detailList = xhStaticsReportService.projectFeeDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<ProjectFeeDetailDTO> util = new ExcelUtil<ProjectFeeDetailDTO>(ProjectFeeDetailDTO.class);
        String sheetName = "各项目运输费用-"+(XHConstant.STR_0.equals(xhStaticsReportQueryVo.getDateFlag())?xhStaticsReportQueryVo.getDateYearMonth():xhStaticsReportQueryVo.getDateYear());
        util.exportExcel(response, detailList, sheetName);
    }

    /** ============================ 各物流公司运输费用 ============================ **/

    /**
     * 各物流公司运输费用-查询
     *
     * @return
     */
    @Log(title = "各物流公司运输费用")
    @GetMapping("/dept/fee/detail/page")
    public TableDataInfo deptFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<DeptFeeDetailDTO> detailList = xhStaticsReportService.deptFeeDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 各项目运输费用-导出
     */
    @Log(title = "各物流公司运输费用-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/dept/fee/detail/export")
    public void deptFeeDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<DeptFeeDetailDTO> detailList = xhStaticsReportService.deptFeeDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<DeptFeeDetailDTO> util = new ExcelUtil<DeptFeeDetailDTO>(DeptFeeDetailDTO.class);
        String sheetName = "各物流公司运输费用-"+(XHConstant.STR_0.equals(xhStaticsReportQueryVo.getDateFlag())?xhStaticsReportQueryVo.getDateYearMonth():xhStaticsReportQueryVo.getDateYear());
        util.exportExcel(response, detailList, sheetName);
    }

    /** ============================ 压车费模板 ============================ **/

    /**
     * 压车费模板-查询
     *
     * @return
     */
    @Log(title = "压车费模板")
    @GetMapping("/load/fee/detail/page")
    public TableDataInfo loadFeeDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<LoadFeeDetailDTO> detailList = xhStaticsReportService.loadFeeDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 各项目运输费用-导出
     */
    @Log(title = "压车费模板-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/load/fee/detail/export")
    public void loadFeeDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<LoadFeeDetailDTO> detailList = xhStaticsReportService.loadFeeDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<LoadFeeDetailDTO> util = new ExcelUtil<LoadFeeDetailDTO>(LoadFeeDetailDTO.class);
        String sheetName = "压车费模板-"+(XHConstant.STR_0.equals(xhStaticsReportQueryVo.getDateFlag())?xhStaticsReportQueryVo.getDateYearMonth():xhStaticsReportQueryVo.getDateYear());
        util.exportExcel(response, detailList, sheetName);
    }

    /** ============================ 物流公司对账单 ============================ **/

    /**
     * 物流公司对账单-查询
     *
     * @return
     */
    @Log(title = "物流公司对账单")
    @GetMapping("/dept/reconciliation/detail/page")
    public TableDataInfo deptReconciliationPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<DeptReconciliationDTO> detailList = xhStaticsReportService.deptReconciliationPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 各项目运输费用-导出
     */
    @Log(title = "物流公司对账单-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/dept/reconciliation/detail/export")
    public void deptReconciliationExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<DeptReconciliationDTO> detailList = xhStaticsReportService.deptReconciliationPage(xhStaticsReportQueryVo);
        ExcelUtil<DeptReconciliationDTO> util = new ExcelUtil<DeptReconciliationDTO>(DeptReconciliationDTO.class);
        util.exportExcel(response, detailList, "物流公司对账单");
    }

    /** ============================ 车间设备发货单种类费用 ============================ **/

    /**
     * 车间设备发货单种类费用-查询
     *
     * @return
     */
    @Log(title = "车间设备发货单种类费用")
    @GetMapping("/device/detail/page")
    public TableDataInfo deviceDetailPage(XhStaticsReportQueryVo xhStaticsReportQueryVo) {
        startPage();
        List<DeviceDetailDTO> detailList = xhStaticsReportService.deviceDetailPage(xhStaticsReportQueryVo);
        return getDataTable(detailList);
    }

    /**
     * 各项目运输费用-导出
     */
    @Log(title = "车间设备发货单种类费用-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/device/detail/export")
    public void deviceDetailExport(HttpServletResponse response, XhStaticsReportQueryVo xhStaticsReportQueryVo)
    {
        List<DeviceDetailDTO> detailList = xhStaticsReportService.deviceDetailPage(xhStaticsReportQueryVo);
        ExcelUtil<DeviceDetailDTO> util = new ExcelUtil<DeviceDetailDTO>(DeviceDetailDTO.class);
        util.exportExcel(response, detailList, "车间设备发货单种类费用");
    }

}
